package com.example.demo1109.demo2;

import com.example.demo1109.demo1.Show;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Broker {
    private Object actor;

    public Broker(Object actor) {
        this.actor = actor;
    }
    public Show getInstance(){
        ClassLoader classLoader = actor.getClass().getClassLoader();
        Class<?>[] interfaces = actor.getClass().getInterfaces();
        InvocationHandler a = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                negotiate();
                extend();
                method.invoke(actor,args);
                acknowledge();
                return null;
            }
        };
        Object o = Proxy.newProxyInstance(classLoader, interfaces, a);
        return (Show) o;
    }
    public void negotiate(){
        System.out.println("洽谈出场费");
    }
    public void extend(){
        System.out.println("向观众问好");
    }
    public void acknowledge(){
        System.out.println("向观众答谢");
    }
}
